package code.cando;

/**
 * author : yeswater
 * date : 2023/12/8
 * <p>
 * 最大子数组和
 * <p>
 * 最大和的连续子数组
 */

public class T053 {
    public int maxSubArray(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int max = nums[0];
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            if (sum >= 0) {
                sum += nums[i];
            } else {
                sum = nums[i];
            }
            max = Math.max(max, sum);
        }
        return max;
    }
}
